from manim import *



class math(Scene):
    def construct(self):
        self.camera.background_color = BLACK  # 设置背景颜色
        self.camera.frame_width = 100  # 设置边框宽度
        self.camera.frame_height = 60  # 设置边框高度
        self.camera.pixel_height = 1080  # 设置像素高度
        self.camera.pixel_width = 1920  # 设置像素宽度
        self.camera.center = ORIGIN  # 设置中心点位置
        self.camera.scale_factor = 1.0  # 设置缩放因子
        #设置横线
        for i in range(6*2+1):       
            dot1=Dot([-50,5*(i-6),0]).set_opacity(0.5)
            dot2=Dot([50,5*(i-6),0]).set_opacity(0.5)
            if i==6:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
                line1.set_stroke(width=10)
            else:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
               
            self.add(dot1,dot2,line1)
        #设置竖线
        for i in range(10*2+1):        
            dot3=Dot([(i-10)*5,-30,0]).set_opacity(0.5)
            dot4=Dot([(i-10)*5,30,0]).set_opacity(0.5)
            if i==10:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
                line2.set_stroke(width=10)
            else:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
            self.add(dot3,dot4,line2)
        #设置三个点
        dot1 = Dot(radius=1, color=RED)  
        dot1.move_to([-47.5,27.5,0]) 
        dot2 = Dot(radius=1, color=YELLOW)  
        dot2.move_to([-42.5,27.5,0])  
        dot3 = Dot(radius=1, color=GREEN)  
        dot3.move_to([-37.5,27.5,0])

         #设置题目并写出
        text0 = Tex(r"\text{计算} $\int \dfrac{1}{1+\cos ^{2}x}dx$ "
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0)
        self.play(Write(text0),FadeIn(dot1),FadeIn(dot2),FadeIn(dot3))

        #题目向上移动
 
        self.play(text0.animate().scale(0.8).move_to(UP*20)) 

        #分析文本
        text=MarkupText("<b><i>分析/解：</i></b>",color=PINK).scale(5.0).move_to([-35,7.5,0])
        self.play(Create(text)) 
        self.wait()
        #箭头引出
        arrow = Arrow(start=[10,25,0],end=[6,23,0], color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow))
        #文本
        long_text=("特征识别:\n"
                     "三角函数伪奇偶")
        text1 = Text(long_text,color=YELLOW,
                   font_size=200).move_to([20,25,0])
        #框框标
        rectangle=Rectangle(color=BLUE,fill_opacity=0.0,width=9,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle.move_to([2, 20, 0])
        self.play(Create(rectangle),Create(text1))
        self.wait()
        #箭头引出
        arrow1 = Arrow(start=[2,17,0],end=[2,10,0], color=RED
                       , stroke_width=20, tip_length=1)
        #文本
        text2 = Tex(r"\text{触发}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([10,13,0])
        self.play(Create(arrow1),Create(text2))
        text3 = Tex(r"\text{凑}$d\left( \tan x\right) $"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([2,7,0])
        self.play(Create(text3))
         #框框标
        text4 = Tex(r"\text{对应解法}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([15,7,0])
        
        rectangle1=Rectangle(color=BLUE,fill_opacity=0.0,width=14,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle1.move_to([2, 7, 0])
        self.play(Create(rectangle1),Create(text4))
        self.wait()

        text5 = Tex(r"$\int \dfrac{\dfrac{1}{\cos ^{2}x}}{\dfrac{1}{\cos ^{2}x}+1}dx$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,-5,0])
        self.play(Create(text5))
        self.wait()
        #文本丝滑改变
        text6 = Tex(r"$\int \dfrac{\sec ^{2}x}{\sec ^{2}x+1}dx$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,-5,0])
        text7 = Tex(r"$\int \dfrac{1}{\tan ^{2}x+2}d\tan x$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,-5,0])
        self.play(
            ReplacementTransform(text5,text6)
        )
        self.wait(0.5)
        self.play(
            ReplacementTransform(text6,text7)
        )
        self.wait(0.5)
        text8 = Tex(r"$\int \dfrac{1}{x^{2}+a^{2}}dx=\dfrac{1}{a}\arctan \dfrac{x}{a}+c$"
                    ,color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-30,-10,0])
        self.play(Create(text8))

        self.wait()
        text9 = Tex(r"$=\dfrac{1}{\sqrt{2}}\arctan \dfrac{\tan x}{\sqrt{2}}+c$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([5,-15,0])
        self.play(Create(text9))
        self.wait(0.5)
        #屏幕清除
        self.play(FadeOut(text0,text,text1,text1,text2,text3,text4,text7,text8,text9,rectangle,rectangle1,arrow,arrow1,dot1,dot2,dot3))
        text10=MarkupText("<b><i>Summary：</i></b>",color=PINK).scale(5.0).move_to([-35,17.5,0])
        self.play(Write(text10))
        #设置题目并写出
        text11 = Tex(r"\text{计算} $\int \dfrac{1}{1+\cos ^{2}x}dx$ "
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0) 
        self.play(Write(text11)) 
        self.wait()           
        text12 = Tex(r"\text{计算} $\int _{0}^{\pi }\dfrac{1}{1+\cos ^{2}x}dx?$ "
                    ,color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text11,DOWN,buff=2)
        self.play(Write(text12))




        



        